package com.yxhl.zoume.core.tripsmgmt.ui.fragment.tripsdetail;


import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.afollestad.materialdialogs.DialogAction;
import com.afollestad.materialdialogs.MaterialDialog;
import com.yxhl.protobuf.BizOrder;
import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.Contract;
import com.yxhl.protobuf.OrderBizType;
import com.yxhl.protobuf.OrderPayStatus;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.custom.ListViewWrap;
import com.yxhl.zoume.common.ui.fragment.BaseFragment;
import com.yxhl.zoume.core.func.webpage.info.WebPageEntrance;
import com.yxhl.zoume.core.tripsmgmt.presenter.detail.DetailTripContainerPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.unit.CancelOrderPresenter;
import com.yxhl.zoume.core.tripsmgmt.presenter.zoumebusticket.BusTicketRefundPresenter;
import com.yxhl.zoume.core.tripsmgmt.ui.activity.TripDetailContainerActivity;
import com.yxhl.zoume.core.tripsmgmt.ui.adapter.PassengerDetailAdapter;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.event.CancelTripOrderFromDialogEvent;
import com.yxhl.zoume.core.tripsmgmt.ui.fragment.dialog.GetTicketCodeDialogFragment;
import com.yxhl.zoume.core.tripsmgmt.view.detail.DetailOrderView;
import com.yxhl.zoume.core.tripsmgmt.view.unit.CancelOrderView;
import com.yxhl.zoume.core.tripsmgmt.view.zoumebusticket.BusRefundTicketView;
import com.yxhl.zoume.data.http.model.trips.BusRefundBean;
import com.yxhl.zoume.data.rxbus.RxBus;
import com.yxhl.zoume.di.component.trip.DaggerTripComponent;
import com.yxhl.zoume.di.module.ActivityModule;
import com.yxhl.zoume.di.module.trip.TripModule;
import com.yxhl.zoume.domain.interactor.ZMEventSubscriber;
import com.yxhl.zoume.utils.LOG;
import com.yxhl.zoume.utils.PromptUtils;
import com.yxhl.zoume.utils.ZMDialog;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import rx.functions.Action1;

/**
 * Created by sugarya
 * 新地巴士 详情页    车票bus
 */
public class TicketBusTripDetailFragment extends BaseFragment implements CancelOrderView, DetailOrderView, BusRefundTicketView {

    private static final String TAG = "TicketBusTripDetailFrag";

    //widgets
    //头部站点信息
    @BindView(R.id.rl_include_trip_detail_station_info)
    RelativeLayout stationInfoRl;

    @BindView(R.id.iv_include_trip_detail_station_info_icon)
    ImageView stationInfoIconIv;
    @BindView(R.id.tv_include_trip_detail_station_info_start)
    TextView stationInfoStartTv;
    @BindView(R.id.tv_include_trip_detail_station_info_clock)
    TextView stationInfoClockTv;
    @BindView(R.id.tv_include_trip_detail_station_info_date)
    TextView stationInfoDateTv;
    @BindView(R.id.tv_include_trip_detail_station_info_destination)
    TextView stationInfoDestinationTv;

    //乘客信息栏
    @BindView(R.id.tv_include_trip_detail_passenger_info_count_content)
    TextView passengerInfoCountContentTv;
    @BindView(R.id.iv_include_trip_detail_passenger_info_rotation)
    ImageView passengerInfoArrowIv;

    @BindView(R.id.lvw_ticket_bus_passenger_info_detail)
    ListViewWrap passengerDetailLvw;

    //订单信息栏
    @BindView(R.id.tv_include_trip_detail_order_id_content)
    TextView orderIdContentTv;
    @BindView(R.id.tv_include_trip_detail_order_status_content)
    TextView orderStatusContentTv;
    @BindView(R.id.tv_include_trip_detail_order_create_time_content)
    TextView orderCreateTimeContentTv;
    @BindView(R.id.tv_include_trip_detail_order_payment_fee_content)
    TextView orderPaymentFeeContentTv;
    @BindView(R.id.tv_include_trip_detail_order_payment_shuttle)
    TextView orderPaymentShuttleTv;

    //底栏
    @BindView(R.id.frame_ticket_bus_bottom_container)
    FrameLayout bottomContainerFrame;

    @BindView(R.id.ll_ticket_bus_bottom_created_bar)
    LinearLayout bottomCreatedBarLl;
    @BindView(R.id.tv_ticket_bus_bottom_cancel_order)
    TextView bottomCancelOrderTv;
    @BindView(R.id.tv_ticket_bus_bottom_to_pay)
    TextView bottomToPayTv;

    @BindView(R.id.ll_ticket_bus_bottom_refund_detail_bar)
    LinearLayout bottomRefundDetailBar;

    @BindView(R.id.ll_ticket_bus_bottom_ticket_code_bar)
    LinearLayout bottomTicketCodeBarTv;
    @BindView(R.id.tv_ticket_bus_bottom_ticket_code)
    TextView bottomTicketCodeTv;

    //优惠券
    @BindView(R.id.ll_trip_detail_coupon)
    LinearLayout mLlTripDetailCoupon;  //详情优惠
    @BindView(R.id.tv_trip_detail_coupon_original)
    TextView mTvTripDetailCouponOriginal;  //原价
    @BindView(R.id.tv_trip_detail_coupon_discount)
    TextView mTvTripDetailCouponDiscount;  //差价
    @BindView(R.id.iv_trip_detail_payment_arrow)
    ImageView mIvTripDetailPaymentArrow;  // 展开箭头

    //arguments
    @Inject
    DetailTripContainerPresenter mDetailTripContainerPresenter;
    @Inject
    CancelOrderPresenter mCancelOrderPresenter;
    @Inject
    BusTicketRefundPresenter mBusTicketRefundPresenter;


    /**
     * 上一页传递来的数据
     */
    private BizOrder mBizOrder;
    /**
     * 取消订单等待对话框
     */
    private MaterialDialog mDialogForWaitingCancel;

    private MaterialDialog mDialogForWaiting;

    private MaterialDialog mDialogForRefundTicket;
    /**
     * 乘客列表信息是否展开
     */
    private List<Contract> mPassengerList;
    private PassengerDetailAdapter mPassengerDetailAdapter;
    private boolean needDisplayPassengerList = true;
    private int mFromDegree = 0;
    private int mToDegree = 180;

    public TicketBusTripDetailFragment() {
        // Required empty public constructor
    }

    public static TicketBusTripDetailFragment newInstance(BizOrder bizOrder) {

        Bundle args = new Bundle();
        args.putSerializable(UIConstants.TripContainer.ARGUMENT_KEY_TICKET_BUS_TRIP_DETAIL, bizOrder);
        TicketBusTripDetailFragment fragment = new TicketBusTripDetailFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleArguments();
        onRxBusEvent();
    }

    private void onRxBusEvent() {
        //对话框过来的取消订单
        getSubscription().add(toSubscription(CancelTripOrderFromDialogEvent.class,
                new Action1<CancelTripOrderFromDialogEvent>() {
                    @Override
                    public void call(CancelTripOrderFromDialogEvent cancelTripOrderFromDialogEvent) {
                        if (mCancelOrderPresenter != null) {
                            mCancelOrderPresenter.cancelOrder(mBizOrder.getOrderSerial());
                        }
                    }
                },
                new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        LOG.e(TAG, "throwable=" + throwable.toString());
                        onRxBusEvent();
                    }
                }
        ));
    }

    private void handleArguments() {
        Bundle arguments = getArguments();
        if (arguments != null) {
            mBizOrder = (BizOrder) arguments.getSerializable(UIConstants.TripContainer.ARGUMENT_KEY_TICKET_BUS_TRIP_DETAIL);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = super.onCreateView(inflater, container, savedInstanceState);
        ViewCompat.setTransitionName(stationInfoRl, UIConstants.TripContainer.TRIP_DETAIL_SHARE_ELEMENT);
        mDetailTripContainerPresenter.attachView(this);
        mCancelOrderPresenter.attachView(this);
        mBusTicketRefundPresenter.attachView(this);
        initializeShow(mBizOrder);
        bindData(mBizOrder);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        mDetailTripContainerPresenter.getDetailTripOrder(mBizOrder.getOrderSerial());
    }

    @OnClick(R.id.ll_include_trip_detail_passenger_info)
    public void onPassengerArrowClick(View v) {
        startArrowAnimator();
    }

    private void startArrowAnimator() {
        ValueAnimator passengerArrowAnimator = ObjectAnimator.ofFloat(passengerInfoArrowIv, "rotation", mFromDegree, mToDegree);
        passengerArrowAnimator.setDuration(UIConstants.TRIP_DETAIL_ARROW_ROTATION_DURATION);
        passengerArrowAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animation) {
                super.onAnimationStart(animation);
                if (needDisplayPassengerList) {
                    passengerDetailLvw.setVisibility(View.VISIBLE);
                    mFromDegree = 180;
                    mToDegree = 360;
                } else {
                    passengerDetailLvw.setVisibility(View.GONE);
                    mFromDegree = 0;
                    mToDegree = 180;
                }
                needDisplayPassengerList = !needDisplayPassengerList;
            }
        });
        passengerArrowAnimator.start();
    }

    /**
     * 取消订单
     */
    @OnClick(R.id.tv_ticket_bus_bottom_cancel_order)
    public void onCancelOrderClick(View v) {
        ZMDialog dialog = new ZMDialog.Builder(getActivity())
                .setMessage(getString(R.string.dialog_cancel_trip_order_content))
                .setPositiveMessage(getString(R.string.dialog_confirm))
                .setNegativeMessage(getString(R.string.dialog_cancel))
                .setPositiveClickEvent(new ZMEventSubscriber() {
                    @Override
                    public void onNext(Object o) {
                        super.onNext(o);
                        RxBus.getInstance().send(new CancelTripOrderFromDialogEvent());
                    }
                })
                .setNegativeClickEvent(new ZMEventSubscriber())
                .show();
    }

    /**
     * 去支付
     */
    @OnClick(R.id.tv_ticket_bus_bottom_to_pay)
    public void onBottomToPayClick(View v) {
        LOG.e(TAG, "去支付 onClick");
        getAppComponent().navigator().navigateToPayment(getActivity(), mBizOrder);
    }

    /**
     * 乘车码
     */
    @OnClick(R.id.tv_ticket_bus_bottom_ticket_code)
    public void onBottomTicketCodeBarClick(View v) {
        String verifyCode = mBizOrder.getVerifyCode();
        GetTicketCodeDialogFragment
                .newInstance(verifyCode)
                .show(getActivity().getSupportFragmentManager(), GetTicketCodeDialogFragment.class.getSimpleName());
    }


    /**
     * 乘客须知
     */
    @OnClick(R.id.ll_passenger_notice_bar)
    public void onPassengerNoticeBarClick(View v) {
        getAppComponent().navigator().navigateToWebPageActivity(getActivity(), WebPageEntrance.TICKET_BUS_REFUND_NOTICE);
    }

    /**
     * 申请退票
     */
    @OnClick(R.id.tv_ticket_bus_bottom_refund_order)
    public void onPassengerRefundClick(View v) {


        new MaterialDialog.Builder(getActivity())
                .content("车站将收取退票手续费，如需发票请至车站窗口办理退票，是否确认退票?")
                .title("申请退票")
                .titleColor(Color.BLACK)
                .canceledOnTouchOutside(false)
                .positiveText("确认退票")
                .positiveColor(Color.parseColor("#298bff"))
                .negativeText("不退了")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        isShowWaittingDialog(true);
                        mBusTicketRefundPresenter.applyBusRefundTicket(mBizOrder.getOrderSerial());
                    }
                })
                .show();

    }


    /**
     * 退款进度详情
     */
    @OnClick(R.id.ll_ticket_bus_bottom_refund_detail_bar)
    public void onRefundProcessClick(View v) {
        getAppComponent().navigator().navigateToBusRefundProcessActicity(getActivity(), mBizOrder.getOrderSerial());
    }


    private void initializeShow(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();
        //改变顶部信息
        exchangeStationInfoIcon();
        //改变乘车人箭头状态
        exchangePassengerArrowStyle(bizOrder);
        //改变底部信息栏信息
        exchangeBottomBarStyle(payStatus);
    }

    private void exchangeStationInfoIcon() {
        stationInfoIconIv.setImageResource(R.drawable.ic_bashi_002);
    }

    private void exchangePassengerArrowStyle(BizOrder bizOrder) {
        mPassengerList = bizOrder.getPassengerList();
        OrderBizType bizType = bizOrder.getBizType();

        if (mPassengerList != null && mPassengerList.size() > 0) {
            if (mPassengerDetailAdapter == null) {
                mPassengerDetailAdapter = new PassengerDetailAdapter(
                        mActivity,
                        mPassengerList,
                        getChildFragmentManager(),
                        mBizOrder.getOrderSerial(),
                        bizType
                );
                passengerDetailLvw.setAdapter(mPassengerDetailAdapter);
            } else {
                mPassengerDetailAdapter.notifyDataSetChanged();
            }
            passengerInfoArrowIv.setVisibility(View.VISIBLE);
        } else {
            passengerInfoArrowIv.setVisibility(View.INVISIBLE);
        }
    }

    private void exchangeBottomBarStyle(OrderPayStatus payStatus) {
        switch (payStatus) {
            case CREATED:
                bottomContainerFrame.setVisibility(View.VISIBLE);
                bottomCreatedBarLl.setVisibility(View.VISIBLE);
                bottomTicketCodeBarTv.setVisibility(View.GONE);
                bottomRefundDetailBar.setVisibility(View.GONE);
                break;
            case PAID:
                bottomContainerFrame.setVisibility(View.VISIBLE);
                bottomCreatedBarLl.setVisibility(View.GONE);
                bottomTicketCodeBarTv.setVisibility(View.VISIBLE);
                bottomTicketCodeTv.setText(R.string.trip_detail_ticket_code);
                bottomRefundDetailBar.setVisibility(View.GONE);
                break;
            case OPS_REFUNDING:
            case OPS_NO_REFUND:
            case OPS_REFUND:
                bottomContainerFrame.setVisibility(View.VISIBLE);
                bottomRefundDetailBar.setVisibility(View.VISIBLE);
                bottomCreatedBarLl.setVisibility(View.GONE);
                bottomTicketCodeBarTv.setVisibility(View.GONE);
                break;

            default:
                bottomContainerFrame.setVisibility(View.GONE);
        }
    }

    private void bindData(BizOrder bizOrder) {
        OrderPayStatus payStatus = bizOrder.getPayStatus();

        //头部站点信息
        setStartStation(bizOrder.getStart());
        setDestination(bizOrder.getDestination());
        setStartTimeAndData(bizOrder.getGmtDepart());

        //乘车人数
        setPassengerCount(bizOrder.getAmount());

        //订单状态信息
        setOrderId(bizOrder.getOrderSerial());
        setOrderStatus(payStatus);
        setGmtCreate(bizOrder.getGmtCreate());
        setTotalFee(bizOrder.getTotalFee());
        //coupon
        setCouponInfo(bizOrder);
    }


    private void setCouponInfo(BizOrder bizOrder) {
        mTvTripDetailCouponOriginal.setText("¥" + bizOrder.getOrderTotalFee());
        mTvTripDetailCouponDiscount.setText("－¥" + bizOrder.getDiscountFee());

    }

    /**
     * 显示出发地
     *
     * @param station
     */
    private void setStartStation(String station) {
        if (!TextUtils.isEmpty(station)) {
            stationInfoStartTv.setText(station);
        } else {
            stationInfoStartTv.setText("");
        }
    }

    /**
     * 显示目的地
     *
     * @param station
     */
    private void setDestination(String station) {
        if (!TextUtils.isEmpty(station)) {
            stationInfoDestinationTv.setText(station);
        } else {
            stationInfoDestinationTv.setText("");
        }
    }

    /**
     * 显示出发时刻和日期
     *
     * @param timeStamp
     */
    private void setStartTimeAndData(String timeStamp) {
        if (!TextUtils.isEmpty(timeStamp)) {
            String[] strings = timeStamp.split(" ");
            stationInfoDateTv.setText(strings[0]);
            stationInfoClockTv.setText(strings[1]);
        }
    }

    /**
     * 显示乘客人数
     *
     * @param amount
     */
    private void setPassengerCount(int amount) {
        passengerInfoCountContentTv.setText(amount + "人");
    }

    /**
     * 显示订单编号
     *
     * @param orderId
     */
    private void setOrderId(String orderId) {
        if (!TextUtils.isEmpty(orderId)) {
            orderIdContentTv.setText(orderId);
        }
    }

    /**
     * 显示行程状态
     *
     * @param payStatus
     */
    private void setOrderStatus(OrderPayStatus payStatus) {
        String orderStatusStr;
        switch (payStatus) {
            case CREATED:
                orderStatusStr = getString(R.string.trip_detail_pay_status_created);
                break;
            case PAID:
                orderStatusStr = getString(R.string.trip_detail_pay_status_paid);
                break;
            case PAY_INVALID:
                orderStatusStr = getString(R.string.trip_detail_pay_status_invalid);
                break;
            case OPS_REFUNDING:
            case OPS_NO_REFUND:
                orderStatusStr = getString(R.string.trip_detail_pay_status_refunding);
                break;
            case OPS_REFUND:
                orderStatusStr = getString(R.string.trip_detail_pay_status_refund);
                break;
            case ORDER_FINISH:
            case PART_FINISH:
                orderStatusStr = getString(R.string.trip_detail_pay_status_finish);
                break;
            case PAY_CANCEL:
                orderStatusStr = getString(R.string.trip_detail_pay_status_cancel);
                break;
            case OPS_PART_REFUND:
                orderStatusStr = getString(R.string.trip_detail_pay_status_part_refunding);
                break;
            default:
                orderStatusStr = "";
        }
        orderStatusContentTv.setText(orderStatusStr);
    }

    /**
     * 显示下单时间
     *
     * @param time
     */
    private void setGmtCreate(String time) {
        if (!TextUtils.isEmpty(time)) {
            orderCreateTimeContentTv.setText(time);
        }
    }

    /**
     * 显示总费用
     *
     * @param fee
     */
    private void setTotalFee(double fee) {
        if (fee >= 0) {
            orderPaymentFeeContentTv.setText(fee + "元");
        } else {
            orderPaymentFeeContentTv.setText("");
        }
    }

    @Override
    public void renderDetailOrderOnSuccess(BizOrderResponse bizOrderResponse) {
        isShowWaittingDialog(false);
        List<BizOrder> bizOrderList = bizOrderResponse.getOrderFieldsesList();
        if (bizOrderList != null && bizOrderList.size() > 0) {
            BizOrder bizOrder = bizOrderList.get(0);
            if (bizOrder != null) {
                initializeShow(bizOrder);
                bindData(bizOrder);
            }
        }
    }

    @Override
    public void renderDetailOrderOnFailure() {
        isShowWaittingDialog(false);
    }


    @Override
    public void renderCancelOrderResult(boolean isCanceled) {
        if (isCanceled) {
            PromptUtils.showShort(mActivity, getString(R.string.cancel_order_success));
            RxBus.getInstance().send(new CancelTripOrderEvent(mBizOrder.getOrderSerial()));
            mActivity.finish();
        } else {
            PromptUtils.showLong(getActivity(), getString(R.string.trip_cancel_order_failure));
        }
    }

    @Override
    public void renderCancelError() {
        PromptUtils.showShort(mActivity, getString(R.string.trip_cancel_order_error));
    }

    @Override
    public void waitingForOrderCancel(boolean isWaiting) {
        if (isWaiting) {
            mDialogForWaitingCancel = new MaterialDialog.Builder(getActivity())
                    .content(R.string.dialog_waiting_canceling)
                    .progress(true, 0)
                    .canceledOnTouchOutside(false)
                    .show();
        } else {
            if (null != mDialogForWaitingCancel) {
                mDialogForWaitingCancel.dismiss();
            }
        }
    }

    @Override
    protected void initializeInjector() {
        DaggerTripComponent
                .builder()
                .appComponent(getAppComponent())
                .activityModule(new ActivityModule(mActivity))
                .tripModule(new TripModule())
                .build()
                .inject(this);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.fragment_ticket_bus_trip_detail;
    }

    @Override
    protected void setupToolBar() {
        ((TripDetailContainerActivity) mActivity).setToolbar(getString(R.string.trip_detail_header_title), R.drawable.icon_share);
    }

    @OnClick(R.id.ll_include_trip_detail_order_payment_fee)
    public void onDetailCuoponClick() {
        int visibility = mLlTripDetailCoupon.getVisibility();
        if (visibility == View.GONE) {
            mLlTripDetailCoupon.setVisibility(View.VISIBLE);
            triangleAnimationStart();
        } else {
            mLlTripDetailCoupon.setVisibility(View.GONE);
            triangleAnimationEnd();
        }

    }

    private void triangleAnimationStart() {
        RotateAnimation rotateAnimation = new RotateAnimation(0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }

    private void triangleAnimationEnd() {
        RotateAnimation rotateAnimation = new RotateAnimation(180, 360, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        rotateAnimation.setDuration(200);
        rotateAnimation.setFillAfter(true);
        mIvTripDetailPaymentArrow.startAnimation(rotateAnimation);
    }


    /**
     * 退票
     *  @param
     * @param busRefundBean
     */
    @Override
    public void renderRefundApplyOnSuccess(BusRefundBean busRefundBean) {
        isShowWaittingDialog(false);
        ShowRefundTicketDialog(busRefundBean);
    }

    @Override
    public void renderRefundApplyOnFailure(String resultMessage) {
        isShowWaittingDialog(false);
        PromptUtils.showShort(getActivity(), resultMessage);
    }

    @Override
    public void renderRefundApplyOnError(String message) {
        isShowWaittingDialog(false);
        PromptUtils.showShort(getActivity(), "网络繁忙，请稍后再试");
    }

    @Override
    public void renderRefundConfirmOnSuccess(String message) {
        PromptUtils.showShort(getActivity(),message);
        mDetailTripContainerPresenter.getDetailTripOrder(mBizOrder.getOrderSerial());
    }

    @Override
    public void renderRefundConfirmOnFailure(String resultMessage) {
        isShowWaittingDialog(false);
        PromptUtils.showShort(getActivity(), resultMessage);
    }

    @Override
    public void renderRefundConfirmOnError(String message) {
        isShowWaittingDialog(false);
        PromptUtils.showShort(getActivity(), "网络繁忙，请稍后再试");
    }

    private void isShowWaittingDialog(boolean isShow) {

        if (isShow) {
            mDialogForWaiting = new MaterialDialog.Builder(getActivity())
                    .content("正在处理... ...")
                    .progress(true, 0)
                    .canceledOnTouchOutside(false)
                    .show();
        } else {
            if (null != mDialogForWaiting) {
                mDialogForWaiting.dismiss();
            }
        }

    }

    private void ShowRefundTicketDialog(BusRefundBean busRefundBean) {

        mDialogForRefundTicket = new MaterialDialog.Builder(getActivity())
                .content("订单总金额：" + busRefundBean.getTotalFee() + "元\n" +
                        "实退款金额：" + busRefundBean.getRefundFee() + "元\n" +
                        "退款手续费：" + busRefundBean.getLcMoney() + "元\n")
                .title("退款详情")
                .titleColor(Color.BLACK)
                .canceledOnTouchOutside(false)
                .positiveText("确认退票")
                .positiveColor(Color.parseColor("#298bff"))
                .negativeText("不退了")
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        mBusTicketRefundPresenter.confirmBusRefundTicket(mBizOrder.getOrderSerial());
                        isShowWaittingDialog(true);
                    }
                })
                .show();


    }
}
